<!DOCTYPE html>

<html>
<head>
  <title>Type</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="Array.coffee.html">
                Array.coffee.md
              </a>
            
              
              <a class="source" href="BareObject.coffee.html">
                BareObject.coffee.md
              </a>
            
              
              <a class="source" href="Boolean.coffee.html">
                Boolean.coffee.md
              </a>
            
              
              <a class="source" href="Function.coffee.html">
                Function.coffee.md
              </a>
            
              
              <a class="source" href="Math.coffee.html">
                Math.coffee.md
              </a>
            
              
              <a class="source" href="Maybe.coffee.html">
                Maybe.coffee.md
              </a>
            
              
              <a class="source" href="Nullable.coffee.html">
                Nullable.coffee.md
              </a>
            
              
              <a class="source" href="Number.coffee.html">
                Number.coffee.md
              </a>
            
              
              <a class="source" href="Object.coffee.html">
                Object.coffee.md
              </a>
            
              
              <a class="source" href="Promise.coffee.html">
                Promise.coffee.md
              </a>
            
              
              <a class="source" href="String.coffee.html">
                String.coffee.md
              </a>
            
              
              <a class="source" href="Type.coffee.html">
                Type.coffee.md
              </a>
            
              
              <a class="source" href="header.coffee.html">
                header.coffee.md
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <h1 id="type">Type</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	<span class="hljs-built_in">window</span>.Type = <span class="hljs-function"><span class="hljs-title">Type</span> = <span class="hljs-params">(constructor)</span> -&gt;</span>
		<span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span> fn.extend
			<span class="hljs-attribute">matches</span>: Object.isa constructor
	
	Type.union = Function.From(Function).Returning(<span class="hljs-function">-&gt;</span> <span class="hljs-class"><span class="hljs-keyword">class</span>) \</span>
		<span class="hljs-function"><span class="hljs-params">(type)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span>
		
			fn = Function.To(Object.Of Function) fn
		
			<span class="hljs-function"><span class="hljs-title">subtype</span> = <span class="hljs-params">(constructor)</span> -&gt;</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">type</span></span>
				<span class="hljs-attribute">constructor</span>: ( constructor <span class="hljs-keyword">or</span><span class="hljs-function"> -&gt;</span> )
				
			subtypes = fn.call type
			
			<span class="hljs-keyword">if</span> subtypes <span class="hljs-keyword">instanceof</span> Array
				<span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> subtypes
					<span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span> type[name] = subtype<span class="hljs-function"> -&gt;</span>
			<span class="hljs-keyword">else</span>
				<span class="hljs-keyword">for</span> name, constructor <span class="hljs-keyword">of</span> fn.call type
					<span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(name,constructor)</span> -&gt;</span> type[name] = subtype constructor</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
